package com.example.demo.service.impl;

import com.example.demo.entity.Result;
import com.example.demo.mapper.ProjectMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
public class ProjectServiceImpl {
    @Autowired
    private ProjectMapper projectMapper;
    public Result getAllCust(Map<String, Object> params) {
        Integer pageIndex=Integer.parseInt(params.get("pageIndex").toString())-1;
        Integer pageSize=Integer.parseInt(params.get("pageSize").toString());
        params.put("pageIndex",pageIndex*pageSize);
        params.put("pageSize",pageSize);
        List<Map<String,Object>> list=projectMapper.getAllCust(params);
        int count=projectMapper.getCustCont();
        return Result.ok(list).setRecordsCount((long) count);
    }

    @Transactional
    public Result insertCust(Map<String, Object> params) {
        projectMapper.insertCust(params);
        return Result.ok("新增客户成功");
    }
    @Transactional
    public Result updateCust(Map<String, Object> params) {
        projectMapper.updateCust(params);
        return Result.ok("维护客户成功");
    }

    public Result getProject(Map<String, Object> params) {
        Integer pageIndex=Integer.parseInt(params.get("pageIndex").toString())-1;
        Integer pageSize=Integer.parseInt(params.get("pageSize").toString());
        params.put("pageIndex",pageIndex*pageSize);
        params.put("pageSize",pageSize);
        List<Map<String,Object>> list=projectMapper.getProject(params);
        int count=projectMapper.getProjectCont();
        return Result.ok(list).setRecordsCount((long) count);
    }

    @Transactional
    public Result insertProject(Map<String, Object> params) {
        projectMapper.insertProject(params);
        return Result.ok("项目保存成功");
    }

    public Result getAllCust1(Map<String, Object> params) {
        List<Map<String,Object>> list=projectMapper.getAllCust1(params);
        return Result.ok(list);
    }

    public Result updateProject(Map<String, Object> params) {
        projectMapper.updateProject(params);
        return Result.ok("项目维护成功");
    }

    public Result insertProjectFollow(Map<String, Object> params) {
        int num=projectMapper.getFollNum(params);
        params.put("num",num);
        projectMapper.insertProjectFollow(params);
        return Result.ok("项目跟踪成功");
    }

    public Result getProjectFollow(Map<String, Object> params) {
        List<Map<String,Object>> list=projectMapper.getProjectFollow(params);
        return Result.ok(list);
    }

    public Result getSalePlan(Map<String, Object> params) {
        Integer pageIndex=Integer.parseInt(params.get("pageIndex").toString())-1;
        Integer pageSize=Integer.parseInt(params.get("pageSize").toString());
        params.put("pageIndex",pageIndex*pageSize);
        params.put("pageSize",pageSize);
        List<Map<String,Object>> list=projectMapper.getSalePlan(params);
        int count=projectMapper.getSaleCount();
        return Result.ok(list).setRecordsCount((long) count);
    }

    public Result insertSalePlan(Map<String, Object> params) {
        projectMapper.insertSalePlan(params);
        return Result.ok("新增方案计划成功");
    }

    public Result getProject1(Map<String, Object> params) {
        List<Map<String,Object>> list=projectMapper.getProject1(params);
        return Result.ok(list);
    }
}
